﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Threading;
using System.Reflection; // 引用这个才能使用Missing字段
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Xml;
using System.Web;
using System.Runtime.InteropServices;
using System.IO;
using System.Net;
using System.Collections;
using System.Xml.Serialization;

using Newtonsoft.Json;
using LitJson;
using Newtonsoft.Json.Linq;

namespace weiqijiance
{
    public partial class TESTZYJS : Form
    {
        public mainform m_mainform;
        /// <summary>
        /// 结果变量
        /// </summary>
        public float fSK1;
        public float fSK2;
        public float fSK3;
        public float fSK4;
        public float fSKPJ;
        public float fDSZS;

        public float fwendu;
        public float fshidu;
        public float fdaqiya;
        /// <summary>
        ///限值变量
        /// </summary>

        public float fSKXZ;


        public string xianshineirong;
        public float fZS;
        public string fcyzsqz;
        public bool ZYJS_Stop;
        public bool ZYJS_Start;


        public Thread t1;
        public Thread t2;
        public Thread t3;
        public bool bfh = false;

        // /声明INI文件的写操作函数 WritePrivateProfileString()
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        //声明INI文件的读操作函数 GetPrivateProfileString()
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        private string sPath = null;



        /// <summary>
        /// /联网内容
        /// </summary>
        public static string timeStart;
        public static string timeEnd;
        public static string businessId;
        public static string registCode;
        public static string SceneCode;
        public int DETECT_ID = 0;

        public string ssfyqyw;//是否要求油温检测


        public string[] scolorname;
        public TextBox[] m_tex;

        public string[] sBJname;
        public string[] sBJnamecolor;


        string[] OBD_jqmkd = new string[1000];
        string[] OBD_fh = new string[1000];
        string[] OBD_qycgqxh = new string[1000];
        string[] OBD_glkqxs = new string[1000];
        string[] OBD_ymkd = new string[1000];
        string[] OBD_cs = new string[1000];
        string[] OBD_fdjzs = new string[1000];
        string[] OBD_jql = new string[1000];
        string[] OBD_jqyl = new string[1000];
        string[] OBD_scgl = new string[1000];
        string[] OBD_zyyl = new string[1000];
        string[] OBD_hyl = new string[1000];
        string[] OBD_no = new string[1000];
        string[] OBD_nsbsl = new string[1000];
        string[] OBD_pqwd = new string[1000];
        string[] OBD_klbjqyc = new string[1000];
        string[] OBD_egrkd = new string[1000];
        string[] OBD_rypsyl = new string[1000];
        string[] OBD_sjxl = new string[1000];
        public int iobd;

        float[,] m_SKGCSJK = new float[4, 13];
        float[,] m_SKGCSJNO = new float[4, 13];
        float[,] m_SKGCSJTurn = new float[4, 13];
        string[,] m_SKGCSJTime = new string[4, 13];
        float[,] m_SKGCSJyw = new float[4, 13];
        float[] m_SKTurn = new float[4];

           public int itlsj;
           public DateTime dtl;
           联网通信协议.安车model.GC011 gc011;
           public string shphm;
           public string shpzl;
   


        public TESTZYJS(string sbusinessId, string sregistCode)
        {
            InitializeComponent();
            ZYJS_Start = false;
            businessId = sbusinessId;
            registCode = sregistCode;
            dtl = DateTime.Now;

            bianliangchushihua();
            readshezhiJC();
            readjcxx();
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            showFormUI();
            x = this.Width;
            y = this.Height;
            setTag(this);

            scolorname = new string[14] {"提示框",
                                    "号牌号码",
                                    "额定转速",
                                    "当前转速",
                                    "当前K值",
                                    "温度",
                                    "湿度",
                                    "大气压",
                                    "怠速转速",
                                    "第一次测量值",
                                    "第二次测量值",
                                    "第三次测量值",
                                    "第四次测量值",
                                     "提示信息"};
            m_tex = new TextBox[13] {xinxixianshi,
                                    hphm,
                                    edzs,
                                    trun,
                                    SK,
                                    wendu,
                                    shidu,
                                    daqiya,
                                    dsZS,
                                    SK1,
                                    SK2,
                                    SK3,

                                    SK4};

            sBJname = new string[14] { "窗体背景",
                                        "提示框",
                                        "号牌号码",
                                        "额定转速",
                                        "当前转速",
                                        "当前K值",
                                        "温度",
                                        "湿度",
                                        "大气压",
                                        "怠速转速",
                                        "第一次测量值",
                                        "第二次测量值",
                                        "第三次测量值",
                                        "第四次测量值" };
            sBJnamecolor = new string[14] { "#AABBCC",
                                        "#AABBCC",
                                        "#AABBCC",
                                        "#AABBCC",
                                        "#AABBCC",
                                        "#AABBCC",
                                        "#AABBCC",
                                        "#AABBCC",
                                        "#AABBCC",
                                        "#AABBCC",
                                        "#AABBCC",
                                        "#AABBCC",
                                        "#AABBCC",
                                        "#AABBCC" };

            showTextBoxCOLOR();
            readshezhiBJ();

            showbut();
            timer1.Enabled = true;
            xinxixianshi.Text = string.Format("仪器调零中...");
            skinBut_ksjc.Enabled = false;

        }
        public void showFormUI()
        {
            try
            {
                //this.BackgroundImage = Image.FromFile(@"./ico/主界面背景.jpg");
                //this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                this.ControlBox = false; // 设置不出现关闭按钮 
            }
            catch
            {
            }
        }
        float fedzs = 0;
        /// <summary>
        /// 变量初始化
        /// </summary>
        public void bianliangchushihua()
        {
            fSK1 = 0;
            fSK2 = 0;
            fSK3 = 0;
            fSK4 = 0;
            fSKPJ = 0;
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\车辆信息.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);


            hphm.Text = ReadValue("设置", "车牌号码");
            edzs.Text = ReadValue("设置", "额定转速");
            float.TryParse(edzs.Text, out fedzs);
            shphm = ReadValue("设置", "车牌号码");
            shpzl = ReadValue("设置", "号牌种类");
            mainform.hphm = ReadValue("设置", "车牌号码");
            mainform.hpzl = ReadValue("设置", "号牌种类");

        }
        public void readshezhiJC()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\检测要求设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            fcyzsqz = "是";// ReadValue("设置", "柴油车转速取值");
            ssfyqyw = ReadValue("设置", "油温检测要求");
            

        }
        public void readjcxx()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\检测参数设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
            int.TryParse(ReadValue("设置", "LUG调零时间/秒"), out itlsj);
            if (itlsj < 10)
            {
                itlsj = 30;
            }

        }
        public void showTextBoxCOLOR()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\自由加速工况字体颜色配置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            for (int i = 0; i < 13; i++)
            {
                textbox_xs(m_tex[i], System.Drawing.ColorTranslator.FromHtml(ReadValue("自由加速工况字体颜色配置", scolorname[i])));
            }
            Color tishiziti = System.Drawing.ColorTranslator.FromHtml(ReadValue("自由加速工况字体颜色配置", scolorname[13]));
            label1.ForeColor = tishiziti;
            label2.ForeColor = tishiziti;

            label5.ForeColor = tishiziti;
            label6.ForeColor = tishiziti;
            label7.ForeColor = tishiziti;
            label8.ForeColor = tishiziti;
            label9.ForeColor = tishiziti;
            label10.ForeColor = tishiziti;
            label11.ForeColor = tishiziti;
            label12.ForeColor = tishiziti;
            label13.ForeColor = tishiziti;
            label14.ForeColor = tishiziti;

        }
        public void textbox_xs(TextBox tex, Color cColor)//textbox显示风格
        {

            tex.ForeColor = cColor;

        }

        public void buttton_pic(Button but, string sfile)//按钮控件显示风格
        {
            but.BackgroundImage = Image.FromFile(string.Format(@"{0}", sfile));
            but.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            but.ImageAlign = ContentAlignment.TopLeft;
            but.TextAlign = ContentAlignment.TopRight;
            but.ForeColor = Color.Red;
            but.Font = new System.Drawing.Font("黑体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); ;

        }

        public void readshezhiBJ()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\自由加速工况背景颜色配置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            for (int i = 0; i < 14; i++)
            {
                sBJnamecolor[i] = ReadValue("自由加速工况背景颜色配置", sBJname[i]);

                if (i > 0)
                {
                    textbox_BJ(m_tex[i - 1], System.Drawing.ColorTranslator.FromHtml(sBJnamecolor[i]));
                }
                else
                {
                    groupBox1.BackColor = System.Drawing.ColorTranslator.FromHtml(sBJnamecolor[i]);
                    groupBox2.BackColor = System.Drawing.ColorTranslator.FromHtml(sBJnamecolor[i]);
                    groupBox3.BackColor = System.Drawing.ColorTranslator.FromHtml(sBJnamecolor[i]);
                    groupBox4.BackColor = System.Drawing.ColorTranslator.FromHtml(sBJnamecolor[i]);
                    groupBox5.BackColor = System.Drawing.ColorTranslator.FromHtml(sBJnamecolor[i]);


                }
            }

        }
        public void textbox_BJ(TextBox tex, Color cColor)//textbox显示风格
        {

            tex.BackColor = cColor;

        }
        public void showbut()
        {
            //buttton_pic(kaishijiance, "./ico/开始检测.ico");
            //buttton_pic(zhongzhijiance, "./ico/终止检测.ico");
            //buttton_pic(but_shezhi, "./ico/背景配置.ico");
        }

        #region 控件大小随窗体大小等比例缩放
        private float x;//定义当前窗体的宽度
        private float y;//定义当前窗体的高度
        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;
                if (con.Controls.Count > 0)
                {
                    setTag(con);
                }
            }
        }
        private void setControls(float newx, float newy, Control cons)
        {
            //遍历窗体中的控件，重新设置控件的值
            foreach (Control con in cons.Controls)
            {
                //获取控件的Tag属性值，并分割后存储字符串数组
                if (con.Tag != null)
                {
                    string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
                    //根据窗体缩放的比例确定控件的值
                    con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度
                    con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度
                    con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距
                    con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距
                    Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小
                    con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                    if (con.Controls.Count > 0)
                    {
                        setControls(newx, newy, con);
                    }
                }
            }
        }
        #endregion

        //ini文件
        public void Ini(string path)
        {
            this.sPath = path;
        }
        public void Writue(string section, string key, string value)
        {
            // section=配置节，key=键名，value=键值，path=路径
            WritePrivateProfileString(section, key, value, sPath);
        }
        public string ReadValue(string section, string key)
        {
            // 每次从ini中读取多少字节
            System.Text.StringBuilder temp = new System.Text.StringBuilder(255);

            // section=配置节，key=键名，temp=上面，path=路径
            GetPrivateProfileString(section, key, "", temp, 255, sPath);
            return temp.ToString();
        }
        //ini文件


        private delegate void FlushClient();//代理
        private void xianshi()
        {
            if (this.xinxixianshi.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshi);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.xinxixianshi.Text = string.Format(@"{0}", xianshineirong);
            }
        }
        private void xianshiZS()
        {
            if (this.trun.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiZS);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                //if (fcyzsqz.Contains("不透光"))
                //{
                //    fZS = m_mainform.m_fzhuansuSK;
                //}
                //else
                //{
                //    fZS = m_mainform.m_iTurn;
                //}

                if (rbOBDZS.Checked)
                {
                    m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                    int ifdjzs = 0;
                    int.TryParse(m_mainform.OBD_fdjzs, out ifdjzs);
                    fZS = ifdjzs;
                }
                else
                {
                    fZS = m_mainform.objzsy.m_iGasturn;
                }
                this.trun.Text = string.Format(@"{0}", fZS);
            }
        }
        private void xianshiSK()
        {
            if (this.SK.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiSK);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.SK.Text = string.Format(@"{0}", m_mainform.objbtg.m_fsk);
            }
        }
        private void xianshiSK1()
        {
            if (this.SK1.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiSK1);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.SK1.Text = string.Format(@"{0}", fSK1);
            }
        }
        private void xianshiSK2()
        {
            if (this.SK2.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiSK2);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.SK2.Text = string.Format(@"{0}", fSK2);
            }
        }
        private void xianshiSK3()
        {
            if (this.SK3.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiSK3);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.SK3.Text = string.Format(@"{0}", fSK3);
            }
        }
        private void xianshiSK4()
        {
            if (this.SK4.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiSK4);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.SK4.Text = string.Format(@"{0}", fSK4);
            }
        }
        private void xianshiDSZS()
        {
            if (this.dsZS.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiDSZS);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.dsZS.Text = string.Format(@"{0}", fDSZS);
            }
        }

        private void xianshiWENDU()
        {
            if (this.wendu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiWENDU);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.wendu.Text = string.Format(@"{0}", fwendu);
            }
        }
        private void xianshiSHIDU()
        {
            if (this.shidu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiSHIDU);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.shidu.Text = string.Format(@"{0}", fshidu);
            }
        }
        private void xianshiDAQIYA()
        {
            if (this.daqiya.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiDAQIYA);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.daqiya.Text = string.Format(@"{0}", fdaqiya);
            }
        }
        protected void thisclose()
        {

            this.Invoke(new Action(this.Close));  //使用委托关闭该窗体
        }
        public void StratTest()
        {
            bfh = false;
            DETECT_ID = 0;
            if (m_mainform.IsInt(businessId))
            {
                int.TryParse(businessId, out DETECT_ID);
            }
            m_mainform.objbass.XXTZ("03");//中科开始
            //录像开始
            iobd = 0;
            DateTime dcomfh = DateTime.Now;


            timeStart = DateTime.Now.ToLocalTime().ToString();
            ZYJS_Start = true;
            ZYJS_Stop = false;
            float jczs = 0;
            DateTime dateyw=DateTime.Now;
            Thread.Sleep(1500);
            try
            {
                //油温检测开始
                //if (ssfyqyw.Contains("是"))
                {
                    while (true)
                    {
                        Thread.Sleep(500);
                        xianshineirong = string.Format("当前油温:{0}度不符合测试要求", (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK));
                        xianshi();
                        if ((byw ? fywrg : m_mainform.objbtg.m_fyouwenSK) > 80)
                        {
                            break;
                        }
                    }
                }
                while (true)
                {

                    fDSZS = fZS;
                    xianshiDSZS();
                    xianshineirong = string.Format("{0}。请插入转速", fZS);
                    xianshi();
                    Thread.Sleep(500);
                    if (fZS > 500)//test
                    {
                        break;
                    }
                }

                DateTime dateyw2 = DateTime.Now;
                m_mainform.objbtg.SendDeviceCmd(3);

                model.尾气自检.检测前自检.zijianzyjs objzj = new model.尾气自检.检测前自检.zijianzyjs();

                objzj.dtBeginTime = DateTime.Now.AddMinutes(-3).ToString("yyyy-MM-dd HH:mm:ss");
                objzj.dtEndTime = DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss");
                objzj.nCheckResult = "1";
                objzj.fEnvTemperature = m_mainform.objbtg.m_fWenDu.ToString();
                objzj.fEnvHumidity = m_mainform.objbtg.m_fShiDu.ToString();
                objzj.fEnvPressure = m_mainform.objbtg.m_fYaLi.ToString();
                objzj.nEnvTemperatureOK = "1";
                objzj.nEnvHumidityOK = "1";
                objzj.nEnvPressureOK = "1";
                objzj.dtOilTmpCheckBeginTime = dateyw.ToString("yyyy-MM-dd HH:mm:ss");
                objzj.dtOilTmpCheckEndTime = dateyw2.ToString("yyyy-MM-dd HH:mm:ss");
                objzj.fOilTemperature = ((byw ? fywrg : m_mainform.objbtg.m_fyouwenSK) < 80) ? m_mainform.getRandom(81, 89).ToString() : (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK).ToString();
                objzj.nOilTemperatureResult = "1";
                objzj.fKCheckP0Point = "0";
                //objzj.fKCheckP100Point = "16";
                objzj.fKCheckP100Point = (99f + ((float)m_mainform.getRandom(1, 9) * 0.1f)).ToString();
                objzj.nKCheckP0PointOK = "1";
                objzj.nKCheckP100PointOK = "1";

                m_mainform.objbass.jianceqianzj(businessId, objzj);

                if (m_mainform.objbass.start(businessId, "", "", "", bobdhg) == "0")
                 return;
                m_mainform.objbass.luxiangkaishi(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq");//智慧
                m_mainform.objbass.luxiangkaishi(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh");//智慧
                m_mainform.objbass.luxiangkaishi(businessId, shphm, shpzl, m_mainform.tongdaozhong, "wqqj");//智慧
                dtgcsj = DateTime.Now;
                //int igcsjcount = 1;
                DateTime dstart = DateTime.Now;
                float[] m_fAbsorb = new float[4];

                for (int i = 0; i < 3; i++)
                {
                    while (true)
                    {
                        Thread.Sleep(500);


                        fwendu = m_mainform.objbtg.m_fWenDu;
                        fshidu = m_mainform.objbtg.m_fShiDu;
                        fdaqiya = m_mainform.objbtg.m_fYaLi;

                        xianshiWENDU();
                        xianshiSHIDU();
                        xianshiDAQIYA();
                        xianshiDSZS();
                        //xianshiZS();

                        if ((DateTime.Now - dstart).TotalMilliseconds > 1000)
                            break;
                    }
                }

                xianshineirong = "环境采集完毕";
                m_mainform.flowwq.LedWrite("环境采集完毕", "", 1);
                xianshi();
                //图片

                Thread.Sleep(1000);
                xianshineirong = "正在检测怠速转速，请勿踩油门";
                m_mainform.flowwq.LedWrite("正在检测怠速转速", "请勿踩油门", 1);
                xianshi();
                dstart = DateTime.Now;
                while (true)
                {
                    fDSZS = fZS;
                    xianshiDSZS();
                    Thread.Sleep(300);
                    if ((DateTime.Now - dstart).TotalMilliseconds > 5000)
                        break;
                }

                m_mainform.objbass.uploadimage(businessId);
                xianshineirong = "准备吹拂";
                m_mainform.flowwq.LedWrite("准备吹拂", "", 1);
                xianshi();
                Thread.Sleep(1000);
                //三次吹拂
                for (int i = 0; i < 3; i++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        dstart = DateTime.Now;
                        xianshineirong = string.Format(@"第{0}次吹拂 加速3-4秒剩{1} s", i + 1, 3 - k);
                        string sshanghang = string.Format("第{0}次吹拂", i + 1);
                        string sxiahang = string.Format("加速3-4秒剩{0} s", 3 - k);
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                        xianshi();

                        while (true)
                        {
                            Thread.Sleep(900);
                            if ((DateTime.Now - dstart).TotalMilliseconds > 800)
                                break;

                        }

                    }


                    if (i == 0)
                    {
                        xianshineirong = "第一次吹拂 减速到怠速";
                        string sshanghang = string.Format("第一次吹拂完成");
                        string sxiahang = string.Format("减速到怠速");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);


                    }
                    else if (i == 1)
                    {
                        xianshineirong = "第二次吹拂 减速到怠速";
                        string sshanghang = string.Format("第二次吹拂完成");
                        string sxiahang = string.Format("减速到怠速");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

                    }
                    else if (i == 2)
                    {
                        xianshineirong = "第三次吹拂 减速到怠速";
                        string sshanghang = string.Format("第三次吹拂完成");
                        string sxiahang = string.Format("减速到怠速");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

                    }

                    if (i < 3)
                    {
                        for (int k = 0; k < 10; k++)
                        {
                            dstart = DateTime.Now;
                            xianshineirong = string.Format(@"{0}秒后加速", 10 - k);

                            string sshanghang = string.Format(@"{0}秒后加速", 10 - k);
                            m_mainform.flowwq.LedWrite(sshanghang, "", 1);
                            xianshi();


                            while (true)
                            {
                                Thread.Sleep(900);
                                if ((DateTime.Now - dstart).TotalMilliseconds > 800)
                                    break;

                            }

                        }
                    }


                }
                //

                bsenddate = true;
                //
                for (int i = 0; i < 4; i++)
                {
                    dstart = DateTime.Now;
                    m_fAbsorb[i] = 0;

                    for (int k = 0; k < 3; k++)
                    {
                        dstart = DateTime.Now;
                        while (true)
                        {
                            if (ZYJS_Stop)
                            {
                                m_mainform.flowwq.LedWrite("停止检测", "", 1);
                                xianshineirong = string.Format(@"停止检测");
                                xianshi();
                                return;
                            }
                            xianshineirong = string.Format(@"第{0}次检测 油门1s快速到底剩{1} s", i + 1, 3 - k);
                            string sshanghang = string.Format("第{0}次检测", i + 1);
                            string sxiahang = string.Format("加速3-4秒剩{0} s", 3 - k);
                            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                            xianshi();


                            if (!bzsbw && fedzs > fZS)
                            {
                                continue;
                            }
                            m_mainform.baocunrijiGCSJ(string.Format("{0}第{1}次自由加速加速过程数据日志", hphm.Text, i + 1),
                            string.Format("K:{0},转速;{1},油温:{2}", m_mainform.objbtg.m_fsk, fZS, (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK)));

                            //xianshiSK();
                            //xianshiZS();
                            if (jczs < fZS)
                            {
                                jczs = fZS;
                                fDSZS = jczs;
                                xianshiDSZS();
                            }


                            if (m_mainform.jzjskz.Contains("否"))
                            {
                                if (m_mainform.objbtg.m_fsk < 0.01)
                                {
                                    m_mainform.objbtg.m_fsk = ((float)m_mainform.getRandom(1, 3)) / 100f;
                                }
                                if (k > 0 && m_SKGCSJK[i, k - 1] == m_mainform.objbtg.m_fsk)
                                {
                                    m_mainform.objbtg.m_fsk = m_mainform.objbtg.m_fsk + 0.01f;
                                }
                            }
                            m_SKGCSJK[i, k] = m_mainform.objbtg.m_fsk;
                            m_SKGCSJNO[i, k] = m_mainform.objbtg.m_fnosk;
                            m_SKGCSJTurn[i, k] = fZS;
                            m_SKGCSJyw[i, k] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                            m_SKGCSJTime[i, k] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                            if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                            {
                                xianshineirong = string.Format(@"找不到OBD过程数据，请接好OBD再上线！");
                                string sshanghangx = string.Format("OBD可能掉落");
                                string sxiahangx = string.Format("接好OBD再上线");
                                m_mainform.flowwq.LedWrite(sshanghangx, sxiahangx, 1);
                                xianshi();
                                return;
                            }
                            iobd = i * 13 + k;
                            OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                            OBD_fh[iobd] = m_mainform.OBD_fh;
                            OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                            OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                            OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                            OBD_cs[iobd] = m_mainform.OBD_cs;
                            OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                            OBD_jql[iobd] = m_mainform.OBD_jql;
                            OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                            OBD_scgl[iobd] = m_mainform.OBD_scgl;
                            OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                            OBD_hyl[iobd] = m_mainform.OBD_hyl;
                            OBD_no[iobd] = m_mainform.OBD_no;
                            OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                            OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                            OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                            OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                            OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                            OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");


                            if (m_fAbsorb[i] < m_mainform.objbtg.m_fsk)
                                m_fAbsorb[i] = m_mainform.objbtg.m_fsk;



                            Thread.Sleep(500);
                            if ((DateTime.Now - dstart).TotalMilliseconds > 1000)
                            {
                                if (i > 0)
                                {
                                    //
                                    //if (m_mainform.sconnetname.Contains("云景"))
                                    {
                                        //JsonData value = new LitJson.JsonData();
                                        //value["InspectionNum"] = businessId;
                                        //value["SceneCode"] = m_mainform.lineCode;
                                        //value["ProcessTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                        //value["Second_NO"] = iobd - 13;
                                        //value["Flow_RotateSpeed"] = fZS;
                                        //value["Flow_K"] = m_mainform.objbtg.m_fsk;
                                        //value["EnvirTemperature"] = m_mainform.objbtg.m_fWenDu;
                                        //value["EnvirAirPressure"] = m_mainform.objbtg.m_fYaLi;
                                        //value["EnvirHumidity"] = m_mainform.objbtg.m_fShiDu;
                                        //value["EngineOilTemperature"] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                                        //value["GKLX"] = string.Format("{0}", i);

                                        //string svalue = value.ToJson();
                                        //sendZYJSGCSJ(businessId, svalue);

                                        //model.ZYJS.ZYJSgcsjZM objgcsjzm = new model.ZYJS.ZYJSgcsjZM();
                                        //objgcsjzm.iobd = iobd - 12;
                                        objgcsjzm.fZS = fZS;
                                        objgcsjzm.m_fsk = m_mainform.objbtg.m_fsk;
                                        objgcsjzm.m_fWenDu = m_mainform.objbtg.m_fWenDu;
                                        objgcsjzm.m_fYaLi = m_mainform.objbtg.m_fYaLi;
                                        objgcsjzm.m_fShiDu = m_mainform.objbtg.m_fShiDu;
                                        objgcsjzm.m_fyouwenSK = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                                        objgcsjzm.GKLX = i;
                                        //objgcsjzm.ProcessTime = dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss");
                                        //sendZYJSGCSJZM(businessId, objgcsjzm);
                                        //if (m_mainform.sfOBD)
                                        //{
                                        //    m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss"), objgcsjzm.iobd);
                                        //}
                                        //igcsjcount++;
                                    }
                                }
                                if (i == 1)
                                    m_mainform.objbass.GetPic("51");//安车拍照发送命令
                                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq", "151");
                                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh", "251");
                                    m_mainform.objbass.GetPic("151");
                                    m_mainform.objbass.GetPic("251");
                                if (i == 2)
                                    m_mainform.objbass.GetPic("52");//安车拍照发送命令
                                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq", "152");
                                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh", "252");
                                    m_mainform.objbass.GetPic("152");
                                    m_mainform.objbass.GetPic("252");
                                if (i == 3)
                                    m_mainform.objbass.GetPic("53");//安车拍照发送命令
                                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq", "153");
                                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh", "253");
                                    m_mainform.objbass.GetPic("153");
                                    m_mainform.objbass.GetPic("253");
                                break;
                            }

                        }
                    }

                    if (i == 0)
                    {
                        xianshineirong = "第一次检测 减速到怠速";
                        string sshanghang = string.Format("第一次检测完成");
                        string sxiahang = string.Format("减速到怠速");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                        fSK1 = m_fAbsorb[i];
                        xianshi();
                        xianshiSK1();
                    }
                    else if (i == 1)
                    {
                        xianshineirong = "第二次检测 减速到怠速";
                        string sshanghang = string.Format("第二次检测完成");
                        string sxiahang = string.Format("减速到怠速");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                        fSK2 = m_fAbsorb[i];
                        xianshi();
                        xianshiSK2();
                    }
                    else if (i == 2)
                    {
                        xianshineirong = "第三次检测 减速到怠速";
                        string sshanghang = string.Format("第三次检测完成");
                        string sxiahang = string.Format("减速到怠速");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                        fSK3 = m_fAbsorb[i];
                        xianshi();
                        xianshiSK3();
                    }
                    else if (i == 3)
                    {
                        xianshineirong = "第四次检测 减速到怠速";
                        string sshanghang = string.Format("第四次检测完成");
                        string sxiahang = string.Format("减速到怠速");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                        fSK4 = m_fAbsorb[i];
                        xianshi();
                        xianshiSK4();
                    }
                    if (i < 3)
                    {
                        for (int k = 0; k < 10; k++)
                        {
                            dstart = DateTime.Now;
                            while (true)
                            {
                                if (ZYJS_Stop)
                                {
                                    m_mainform.flowwq.LedWrite("停止检测", "", 1);
                                    xianshineirong = string.Format(@"停止检测");
                                    xianshi();
                                    return;
                                }
                                xianshineirong = string.Format(@"{0}秒后加速", 10 - k);
                                string sshanghang = string.Format(@"{0}秒后加速", 10 - k);
                                m_mainform.flowwq.LedWrite(sshanghang, "", 1);
                                xianshi();

                                m_mainform.baocunrijiGCSJ(string.Format("{0}自由加速未加速过程数据日志", hphm.Text),
                                string.Format("K:{0},转速;{1},油温:{2}", m_mainform.objbtg.m_fsk, fZS, (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK)));


                                //xianshiSK();

                                //xianshiZS();

                                m_SKGCSJK[i, 3 + k] = m_mainform.objbtg.m_fsk;
                                m_SKGCSJNO[i, 3 + k] = m_mainform.objbtg.m_fnosk;
                                m_SKGCSJTurn[i, 3 + k] = fZS;
                                m_SKGCSJyw[i, 3 + k] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                                m_SKGCSJTime[i, 3 + k] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                                if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                                {
                                    xianshineirong = string.Format(@"找不到OBD过程数据，请接好OBD再上线！");
                                    string sshanghangx = string.Format("OBD可能掉落");
                                    string sxiahangx = string.Format("接好OBD再上线");
                                    m_mainform.flowwq.LedWrite(sshanghangx, sxiahangx, 1);
                                    xianshi();
                                    return;
                                }
                                iobd = i * 13 + 3 + k;
                                OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                                OBD_fh[iobd] = m_mainform.OBD_fh;
                                OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                                OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                                OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                                OBD_cs[iobd] = m_mainform.OBD_cs;
                                OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                                OBD_jql[iobd] = m_mainform.OBD_jql;
                                OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                                OBD_scgl[iobd] = m_mainform.OBD_scgl;
                                OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                                OBD_hyl[iobd] = m_mainform.OBD_hyl;
                                OBD_no[iobd] = m_mainform.OBD_no;
                                OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                                OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                                OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                                OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                                OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                                OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");




                                if (k > 2 && k < 8)
                                {
                                    m_SKTurn[i] = fZS;
                                }
                                Thread.Sleep(500);
                                if ((DateTime.Now - dstart).TotalMilliseconds > 1000)
                                {

                                    if (i > 0)
                                    {
                                        //
                                        //if (m_mainform.sconnetname.Contains("云景"))
                                        {
                                            //JsonData value = new LitJson.JsonData();
                                            //value["InspectionNum"] = businessId;
                                            //value["SceneCode"] = m_mainform.lineCode;
                                            //value["ProcessTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                            //value["Second_NO"] = iobd - 13;
                                            //value["Flow_RotateSpeed"] = fZS;
                                            //value["Flow_K"] = m_mainform.objbtg.m_fsk;
                                            //value["EnvirTemperature"] = m_mainform.objbtg.m_fWenDu;
                                            //value["EnvirAirPressure"] = m_mainform.objbtg.m_fYaLi;
                                            //value["EnvirHumidity"] = m_mainform.objbtg.m_fShiDu;
                                            //value["EngineOilTemperature"] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                                            //value["GKLX"] = string.Format("{0}", i);

                                            //string svalue = value.ToJson();
                                            //sendZYJSGCSJ(businessId, svalue);

                                            //model.ZYJS.ZYJSgcsjZM objgcsjzm = new model.ZYJS.ZYJSgcsjZM();
                                            //objgcsjzm.iobd = iobd - 12;
                                            objgcsjzm.fZS = fZS;
                                            objgcsjzm.m_fsk = m_mainform.objbtg.m_fsk;
                                            objgcsjzm.m_fWenDu = m_mainform.objbtg.m_fWenDu;
                                            objgcsjzm.m_fYaLi = m_mainform.objbtg.m_fYaLi;
                                            objgcsjzm.m_fShiDu = m_mainform.objbtg.m_fShiDu;
                                            objgcsjzm.m_fyouwenSK = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                                            objgcsjzm.GKLX = i;
                                            //objgcsjzm.ProcessTime = dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss");
                                            //sendZYJSGCSJZM(businessId, objgcsjzm);
                                            //if (m_mainform.sfOBD)
                                            //{
                                            //    m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss"), objgcsjzm.iobd);
                                            //}
                                            //igcsjcount++;
                                        }
                                    }
                                    break;
                                }

                            }
                        }
                    }

                    ///保存数据到数据库中。
                    ///



                }
                bthread3 = true;
                xianshineirong = "检测完成";
                xianshi();

                for (int k = 1; k < 4; k++)
                {
                    fSKPJ += m_fAbsorb[k];
                }

                fSKPJ = fSKPJ / 3;

                ///保存数据到数据库中。
                ///
                timeEnd = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                ///保存数据到数据库中。
                #region 数据结果保存到数据库
                string sqlsds = string.Format(@"update Detects_SJE set 
                                                A_BZY1={0},
                                                A_BZY2={1},
                                                A_BZY3={2},
                                                A_BZYAVG={3},
                                                A_BZS={4},
                                                GasWenDu={5},
                                                GasShiDu={6},
                                                GasYaLi={7},
                                                Time_begin='{8}',
                                                Time_end='{9}',
                                                WQPD={10}
                                                where DETECT_ID={11}  or ASM_JYLSH='{12}' ",
                                                m_fAbsorb[1],
                                                m_fAbsorb[2],
                                                m_fAbsorb[3],
                                                fSKPJ,
                                                dsZS.Text,
                                                wendu.Text,
                                                shidu.Text,
                                                daqiya.Text,
                                                timeStart,
                                                timeEnd,
                                                fSKPJ > m_mainform.TypeApprovalLimits ? 2 : 1,
                                                DETECT_ID,
                                                businessId);
                m_mainform.objbass.objdb.InsertDB(sqlsds);
                #endregion
                //
                // 保存过程数据到本地数据库
                baocunGCSJ_ZYJS(businessId, m_mainform.testtimes);
                baocunGCSJ_OBD(businessId);
                // 保存过程数据到本地数据库


                xianshineirong = string.Format(@"自由加速检测结束");
                m_mainform.flowwq.LedWrite(xianshineirong, "", 1);
                xianshi();





                xianshineirong = string.Format(@"合格");
                if (fSKPJ > m_mainform.TypeApprovalLimits)
                {
                    xianshineirong = string.Format(@"不合格");
                }


                //if (m_mainform.sconnetname.Contains("安车"))
                //{
                //    senlwac();
                //}
                //else if (m_mainform.sconnetname.Contains("智慧"))//旧联网模式
                //{
                //    senlwzh();
                //    m_mainform.objbass.luxiangjieshu(businessId, m_mainform.tongdaoqian, "wqq");
                //    m_mainform.objbass.luxiangjieshu(businessId, m_mainform.tongdaohou, "wqh");
                //    m_mainform.objbass.luxiangjieshu(businessId, m_mainform.tongdaozhong, "wqqj");
                //    m_mainform.objbass.LuXiang("01", "http://193.112.138.21:8011/media/20181121/20181121001_1_h0.mp4");
                //    m_mainform.objbass.LuXiang("02", "http://193.112.138.21:8011/media/20181121/20181121001_1_h0.mp4");
                //    m_mainform.objbass.LuXiang("03", "http://193.112.138.21:8011/media/20181121/20181121001_1_h0.mp4");
                //}
                //else//云景的联网
                {
                    bfh=senlwyj();
                    m_mainform.objbass.XXTZ("05");//中科开始
                }
                m_mainform.objbass.luxiangjieshu(businessId, m_mainform.tongdaoqian, "wqq");
                m_mainform.objbass.luxiangjieshu(businessId, m_mainform.tongdaohou, "wqh");
                m_mainform.objbass.luxiangjieshu(businessId, m_mainform.tongdaozhong, "wqqj");
                m_mainform.objbass.GetPIC("151");//不透光烟度法第一次踩油门拍照点前照
                m_mainform.objbass.GetPIC("152");//不透光烟度法第二次踩油门拍照点前照
                m_mainform.objbass.GetPIC("153");//不透光烟度法第三次踩油门拍照点前照
                m_mainform.objbass.GetPIC("251");//不透光烟度法第一次踩油门拍照点后照
                m_mainform.objbass.GetPIC("252");//不透光烟度法第二次踩油门拍照点后照
                m_mainform.objbass.GetPIC("253");//不透光烟度法第三次踩油门拍照点后照
                m_mainform.objbass.LuXiang("01", "http://193.112.138.21:8011/media/20181121/20181121001_1_h0.mp4");
                m_mainform.objbass.LuXiang("02", "http://193.112.138.21:8011/media/20181121/20181121001_1_h0.mp4");
                m_mainform.objbass.LuXiang("03", "http://193.112.138.21:8011/media/20181121/20181121001_1_h0.mp4");
                if (bfh)
                {
                    m_mainform.objbass.insertjcwc(businessId);
                    m_mainform.insertjcwc(businessId);
                    m_mainform.objbass.stop(businessId, (fSKPJ > m_mainform.InspectionLimits ? 0 : 1).ToString());
                }
                

                m_mainform.flowwq.LedWrite("尾气排放检测", xianshineirong, 1);
                xianshi();
                Thread.Sleep(5000);
                m_mainform.flowwq.LedWrite("尾气排放检测", "", 1);
                thisclose();

            }
            catch (Exception ex)
            {
                m_mainform.baocunriji("自由加速", ex.Message.ToString());
            }


        }
        public void senlwac()
        {
            //长沙安车平台
            string cysx = "";
            string ydzds = "";
            string fdjdszs = "";
            string yw = "";
            string sjxl = "";
            string jczt = "";
            string gklx = "1";

            int icount = 1;
            string jcsj = "";
            string gksj = "";


            for (int i = 0; i < 4; i++)
            {
                for (int k = 0; k < 13; k++)
                {
                    if (i == 0 && k < 3)
                    {
                        gklx = "1";
                    }
                    else if (i == 1 && k < 3)
                    {
                        gklx = "2";
                    }
                    else if (i == 2 && k < 3)
                    {
                        gklx = "3";
                    }
                    else if (i == 3 && k < 3)
                    {
                        gklx = "4";
                    }
                    if (k > 2)
                    {
                        gklx = "0";
                    }

                    if (i == 0 && k == 0)
                    {
                        cysx = string.Format(@"{0}", icount);
                        ydzds = string.Format(@"{0}", m_SKGCSJK[i, k]);
                        fdjdszs = string.Format(@"{0}", m_SKGCSJTurn[i, k]);
                        yw = string.Format(@"{0}", 83);
                        sjxl = string.Format(@"{0}", m_SKGCSJTime[i, k]);
                        jczt = string.Format(@"{0}", gklx);
                        icount++;
                    }
                    else
                    {
                        if (i < 3)
                        {
                            cysx = cysx + "," + string.Format(@"{0}", icount);
                            ydzds = ydzds + "," + string.Format(@"{0}", m_SKGCSJK[i, k]);
                            fdjdszs = fdjdszs + "," + string.Format(@"{0}", m_SKGCSJTurn[i, k]);
                            yw = yw + "," + string.Format(@"{0}", 83);
                            sjxl = sjxl + "," + string.Format(@"{0}", m_SKGCSJTime[i, k]);
                            jczt = jczt + "," + string.Format(@"{0}", gklx);
                            icount++;
                        }
                        else
                        {
                            if (k < 3)
                            {
                                cysx = cysx + "," + string.Format(@"{0}", icount);
                                ydzds = ydzds + "," + string.Format(@"{0}", m_SKGCSJK[i, k]);
                                fdjdszs = fdjdszs + "," + string.Format(@"{0}", m_SKGCSJTurn[i, k]);
                                yw = yw + "," + string.Format(@"{0}", 83);
                                sjxl = sjxl + "," + string.Format(@"{0}", m_SKGCSJTime[i, k]);
                                jczt = jczt + "," + string.Format(@"{0}", gklx);
                                icount++;
                            }
                        }
                    }
                }
            }
            jcsj = icount.ToString();
            gksj = "13,13,13,13";

            string vehispara = "";
            string stoubao = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
            stoubao = stoubao + string.Format(@"<root><head><organ>{0}</organ><jkxlh>{1}</jkxlh><jkid>{2}</jkid></head>",
                                                           m_mainform.organ,
                                                          m_mainform.jkxlh,
                                                           "GC005");

            vehispara = stoubao + string.Format(@"<body><vehispara>
                                <jylsh>{0}</jylsh>
                                <testtimes>{1}</testtimes>
                                <cyds>{2}</cyds>
                                <cysx>{3}</cysx>
                                <ydzds>{4}</ydzds>
			                    <fdjdszs>{5}</fdjdszs>
			                    <yw>{6}</yw>
			                    <sjxl>{7}</sjxl>
			                    <jczt>{8}</jczt>
			                    <jcsj>{9}</jcsj>
			                    <gksj>{10}</gksj>
                                 </vehispara>
			                    </body>
                                </root>",
                                businessId,
                                m_mainform.testtimes,
                                42,
                                cysx,
                                ydzds,
                                fdjdszs,
                                yw,
                                sjxl,
                                jczt,
                                jcsj,
                                gksj);


            obdsc();//发送OBD过程数据

            //过程数据
            WebReferenceCS.VeptsOutAccess m_vesd = new WebReferenceCS.VeptsOutAccess();
            m_vesd.Url = m_mainform.surl;

            string sgc005 = m_vesd.write(vehispara);
            if (!sgc005.ToUpper().Contains("<CODE>1</CODE>"))
            {
                m_mainform.baocunRJ("自由加速过程数据", vehispara); //
                m_mainform.baocunRJ("自由加速过程数据结果", m_mainform.decode(sgc005)); //
                return;
            }



            //检测结果
            string vehisparajg = "";
            string stoubaojg = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
            stoubaojg = stoubaojg + string.Format(@"<root><head><organ>{0}</organ><jkxlh>{1}</jkxlh><jkid>{2}</jkid></head>",
                                                     m_mainform.organ,
                                                    m_mainform.jkxlh,
                                                     "JC005");

            vehisparajg = stoubaojg + string.Format(@"<body><vehispara>
                                <jylsh>{0}</jylsh>
                                <testtimes>{1}</testtimes>
                                <wd>{2}</wd>
                                <dqy>{3}</dqy>
                                <xdsd>{4}</xdsd>
			                    <idlerev>{5}</idlerev>
			                    <smokek4>{6}</smokek4>
			                    <smokek3>{7}</smokek3>
			                    <smokek2>{8}</smokek2>
			                    <smokek1>{9}</smokek1>
			                    <smokeavg>{10}</smokeavg>
			                    <result>{11}</result>
			                    <smokeklimit>{12}</smokeklimit>
                                <fdjzs4>{13}</fdjzs4>
                                <fdjzs3>{14}</fdjzs3>
                                <fdjzs2>{15}</fdjzs2>
                                <fdjzs1>{16}</fdjzs1>
                                 </vehispara>
			                    </body>
                                </root>",
                                businessId,
                                m_mainform.testtimes,
                                wendu.Text,
                                daqiya.Text,
                                shidu.Text,
                                dsZS.Text,
                                SK4.Text,
                                SK3.Text,
                                SK2.Text,
                                SK1.Text,
                                fSKPJ,
                                fSKPJ > m_mainform.InspectionLimits ? 0 : 1,
                                m_mainform.InspectionLimits,
                                m_SKTurn[3],
                                m_SKTurn[2],
                                m_SKTurn[1],
                                m_SKTurn[0]);

            string sjg005 = m_vesd.write(vehisparajg);
            if (!sjg005.ToUpper().Contains("<CODE>1</CODE>"))
            {
                m_mainform.baocunRJ("自由加速结果数据", vehisparajg); //
                m_mainform.baocunRJ("自由加速数据结果", m_mainform.decode(sgc005)); //
                return;
            }
            //检测结果
            ///长沙安车平台
            string shege = "1";
            xianshineirong = string.Format(@"合格");
            if (fSKPJ > m_mainform.InspectionLimits)
            {
                xianshineirong = string.Format(@"不合格");
                shege = "0";
            }
            m_mainform.sendjieshuAC(shege);//发送结束
        }
        public void senlwzh()
        {
            联网通信协议.安车model.GC005 gc005 = new 联网通信协议.安车model.GC005();
            联网通信协议.安车model.JC005 jc005 = new 联网通信协议.安车model.JC005();

            string cysx = "";
            string ydzds = "";
            string fdjdszs = "";
            string yw = "";
            string sjxl = "";
            string jczt = "";
            string gklx = "1";
            int icount = 1;
            string jcsj = "";
            string gksj = "";

            for (int i = 0; i < 4; i++)
            {
                for (int k = 0; k < 13; k++)
                {
                    //if (i == 0 && k < 3)
                    //{
                    //    gklx = "1";
                    //}
                    //else if (i == 1 && k < 3)
                    //{
                    //    gklx = "2";
                    //}
                    //else if (i == 2 && k < 3)
                    //{
                    //    gklx = "3";
                    //}
                    //else if (i == 3 && k < 3)
                    //{
                    //    gklx = "4";
                    //}
                    //if (k > 2)
                    //{
                    //    gklx = "0";
                    //}
                    if (icount == 1 || icount == 2 || icount == 3)
                    {
                        gklx = "1";
                    }
                    else if (icount == 14 || icount == 15 || icount == 16)
                    {
                        gklx = "2";
                    }
                    else if (icount == 27 || icount == 28 || icount == 29)
                    {
                        gklx = "3";
                    }
                    else if (icount == 40 || icount == 41 || icount == 42)
                    {
                        gklx = "4";
                    }
                    else
                    {
                        gklx = "0";
                    }
                    if (i == 0 && k == 0)
                    {
                        cysx = string.Format(@"{0}", icount);
                        ydzds = string.Format(@"{0}", m_SKGCSJK[i, k]);
                        fdjdszs = string.Format(@"{0}", m_SKGCSJTurn[i, k]);
                        yw = string.Format(@"{0}", m_SKGCSJyw[i, k]);
                        sjxl = string.Format(@"{0}", m_SKGCSJTime[i, k]);
                        jczt = string.Format(@"{0}", gklx);
                        icount++;
                    }
                    else
                    {
                        if (i < 3)
                        {
                            cysx = cysx + "," + string.Format(@"{0}", icount);
                            ydzds = ydzds + "," + string.Format(@"{0}", m_SKGCSJK[i, k]);
                            fdjdszs = fdjdszs + "," + string.Format(@"{0}", m_SKGCSJTurn[i, k]);
                            yw = yw + "," + string.Format(@"{0}", m_SKGCSJyw[i, k]);
                            sjxl = sjxl + "," + string.Format(@"{0}", m_SKGCSJTime[i, k]);
                            jczt = jczt + "," + string.Format(@"{0}", gklx);
                            icount++;
                        }
                        else
                        {
                            if (k < 3)
                            {
                                cysx = cysx + "," + string.Format(@"{0}", icount);
                                ydzds = ydzds + "," + string.Format(@"{0}", m_SKGCSJK[i, k]);
                                fdjdszs = fdjdszs + "," + string.Format(@"{0}", m_SKGCSJTurn[i, k]);
                                yw = yw + "," + string.Format(@"{0}", m_SKGCSJyw[i, k]);
                                sjxl = sjxl + "," + string.Format(@"{0}", m_SKGCSJTime[i, k]);
                                jczt = jczt + "," + string.Format(@"{0}", gklx);
                                icount++;
                            }
                        }
                    }
                }
            }
            jcsj = icount.ToString();
            gksj = "13,13,13,13";

            gc005.cyds = "42";
            gc005.cysx = cysx;
            gc005.ydzds = ydzds;
            gc005.fdjdszs = fdjdszs;
            gc005.yw = yw;
            gc005.sjxl = sjxl;
            gc005.jczt = jczt;
            gc005.jcsj = jcsj;
            gc005.gksj = gksj;

            obdsc();//发送OBD过程数据

            jc005.wd = wendu.Text;
            jc005.dqy = daqiya.Text;
            jc005.xdsd = shidu.Text;
            jc005.idlerev = dsZS.Text;
            jc005.enginespeed = edzs.Text;
            jc005.fdjzs4 = m_SKTurn[3].ToString("0");
            jc005.fdjzs3 = m_SKTurn[2].ToString("0");
            jc005.fdjzs2 = m_SKTurn[1].ToString("0");
            jc005.fdjzs1 = m_SKTurn[0].ToString("0");
            jc005.smokek4 = SK4.Text;
            jc005.smokek3 = SK3.Text;
            jc005.smokek2 = SK2.Text;
            jc005.smokek1 = SK1.Text;
            jc005.smokeavg = fSKPJ.ToString("0.00");
            jc005.result = (fSKPJ > m_mainform.InspectionLimits ? 0 : 1).ToString();
            jc005.smokeklimit = (m_mainform.InspectionLimits).ToString("0.0");


            string neirong = m_mainform.objbass.uploadZYJS(gc005, gc011, jc005);
            if (neirong.Trim().Length > 0)
            {
                xianshineirong = neirong;
                xianshi();
                return;
            }
            xianshineirong = string.Format(@"合格");
            if (fSKPJ > m_mainform.InspectionLimits)
            {
                xianshineirong = string.Format(@"不合格");
            }
            m_mainform.objbass.SendMessage("05", "结束检测");
        }
        public bool senlwyj()
        {
            model.ZYJS.ZYJSsj objsj = new model.ZYJS.ZYJSsj();

            objsj.fwendu = fwendu;
            objsj.fdaqiya = fdaqiya;
            objsj.fshidu = fshidu;
            float.TryParse(SK2.Text, out objsj.SK1);
            float.TryParse(SK3.Text, out objsj.SK2);
            float.TryParse(SK4.Text, out objsj.SK3);
            float.TryParse(SK1.Text, out objsj.SK4);
            objsj.fSKPJ = fSKPJ;
            int.TryParse(m_SKTurn[0].ToString("0"), out objsj.m_SKTurn);
            objsj.m_SKTurn = (int)fDSZS;
            int.TryParse(m_SKTurn[1].ToString("0"), out objsj.m_SKTurn2);
            int.TryParse(m_SKTurn[2].ToString("0"), out objsj.m_SKTurn3);
            int.TryParse(m_SKTurn[3].ToString("0"), out objsj.m_SKTurn4);
            objsj.smokeklimit = m_mainform.InspectionLimits;
            objsj.result = fSKPJ < m_mainform.InspectionLimits ? "1" : "0";
            objsj.idlerev = edzs.Text;

            objsj.InspectTime=78;//	int	总检测时间（多少秒）
            objsj.WorkTime=39;//int	工况时间（多少秒）
            int.TryParse(edzs.Text, out objsj.EngRev);

            model.ZYJS.ZYJSgcsj objgcsj = new model.ZYJS.ZYJSgcsj();
            objgcsj.m_SKGCSJTurn = m_SKGCSJTurn;
            objgcsj.m_SKGCSJK = m_SKGCSJK;
            objgcsj.m_SKGCSJyw = m_SKGCSJyw;
            objgcsj.m_SKGCSJTime = m_SKGCSJTime;

            //OBD
            model.LUG.LUGobdgcsj objobdgcsj = new model.LUG.LUGobdgcsj();
            objobdgcsj.ObdThrottle = OBD_jqmkd;
            objobdgcsj.ObdSpeed = OBD_cs;
            objobdgcsj.ObdPower = OBD_scgl;
            objobdgcsj.ObdRPM = OBD_fdjzs;
            objobdgcsj.ObdAirInput = OBD_jql;
            objobdgcsj.ObdBoostPressure = OBD_zyyl;
            objobdgcsj.ObdFuelConsumption = OBD_hyl;
            objobdgcsj.ObdNOx = OBD_no;
            objobdgcsj.ObdSCR = OBD_nsbsl;
            objobdgcsj.ObdEGT = OBD_pqwd;
            objobdgcsj.ObdDPF = OBD_klbjqyc;
            objobdgcsj.ObdEGR = OBD_egrkd;
            objobdgcsj.ObdEFI = OBD_rypsyl;
            objobdgcsj.ObdAirPressure = OBD_jqyl;//新增
            objobdgcsj.ObdExcessAirFactor = OBD_glkqxs;//新增
            objobdgcsj.ObdPreOxygen = OBD_qycgqxh;//新增
            objobdgcsj.ObdCLV = OBD_fh;//新增
            objobdgcsj.Obdsjxl = OBD_sjxl;//新增
            objobdgcsj.Obdymkd = OBD_ymkd;//新增



            string message = m_mainform.objbass.sjuploadZYJS(businessId, objsj, objgcsj, objobdgcsj);
            if (!message.Contains("1"))
            {
                xianshineirong = message;
                xianshi();
                Thread.Sleep(3000);
                return false;
            }
            return true;
        }
        public void Thread1()
        {
            StratTest();
            ZYJS_tz = true;
        }
        bool ZYJS_tz = false;
        public void Thread2()
        {

            while (true)
            {
                if (ZYJS_tz)
                {
                    break;
                }
                m_mainform.objbtg.SendDeviceCmd(3);
                //m_mainform.SendDeviceCmdSK();
                Thread.Sleep(500);


                xianshiSK();
                xianshiZS();
            }


        }
        public bool bthread3 = false;
        public bool bthread_time = false;
        public bool bsenddate = false;
        public DateTime sendDate;
        public DateTime sendDate2;
        public DateTime dtgcsj;
        public int igcsjcount_obd = 1;
        public int igcsjcount = 1;
        model.ZYJS.ZYJSgcsjZM objgcsjzm = new model.ZYJS.ZYJSgcsjZM();
        model.LUG.LUGobdgcsj objasmobds = new model.LUG.LUGobdgcsj();
        public void Thread3()
        {
            int icountobdds = 0;
            //if (!m_mainform.sconnetname.Contains("安车") && !m_mainform.sconnetname.Contains("智慧"))
            {
                while (true)
                {
                    Thread.Sleep(300);
                    //
                    if (bsenddate)
                    {
                        if (m_mainform.DateDiff(DateTime.Now, sendDate) > 900 && !bthread_time)
                        {
                            bthread_time = true;
                            sendDate = DateTime.Now;
                            objgcsjzm.ProcessTime = dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss");
                            objgcsjzm.iobd = igcsjcount;

                            if (m_mainform.objbass.zmgcsjzyjs(businessId, objgcsjzm).Contains("1"))
                            {
                                igcsjcount++;
                            }
                            if (m_mainform.sfOBD)
                            {

                                if (m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(igcsjcount_obd).ToString("yyyy-MM-dd HH:mm:ss"), igcsjcount_obd).Contains("1"))
                                {
                                    igcsjcount_obd++;
                                }
                            }

                            bthread_time = false;
                        }
                    }
                    DateTime dtimeobddq = DateTime.Now;
                    if (icountobdds > 0 && dtimeobddq.ToString("yyyy-MM-dd HH:mm:ss") == objasmobds.obdjcsj[icountobdds - 1])
                    {
                        icountobdds--;
                    }
                    if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                    {
                    }
                    objasmobds.ObdThrottle[icountobdds] = m_mainform.OBD_ymkd.Length < 1 ? "0" : m_mainform.OBD_ymkd;
                    objasmobds.ObdSpeed[icountobdds] = m_mainform.OBD_cs.Length < 1 ? "0" : m_mainform.OBD_cs;
                    objasmobds.ObdPower[icountobdds] = m_mainform.OBD_scgl.Length < 1 ? "0" : m_mainform.OBD_scgl;
                    objasmobds.ObdRPM[icountobdds] = m_mainform.OBD_fdjzs.Length < 1 ? "0" : m_mainform.OBD_fdjzs;
                    objasmobds.ObdAirInput[icountobdds] = m_mainform.OBD_jql.Length < 1 ? "0" : m_mainform.OBD_jql;
                    objasmobds.ObdBoostPressure[icountobdds] = m_mainform.OBD_zyyl.Length < 1 ? "0" : m_mainform.OBD_zyyl;
                    objasmobds.ObdFuelConsumption[icountobdds] = m_mainform.OBD_hyl.Length < 1 ? "0" : m_mainform.OBD_hyl;
                    objasmobds.ObdNOx[icountobdds] = m_mainform.OBD_no.Length < 1 ? "0" : m_mainform.OBD_no;
                    objasmobds.ObdSCR[icountobdds] = m_mainform.OBD_nsbsl.Length < 1 ? "0" : m_mainform.OBD_nsbsl;
                    objasmobds.ObdEGT[icountobdds] = m_mainform.OBD_pqwd.Length < 1 ? "0" : m_mainform.OBD_pqwd;
                    objasmobds.ObdDPF[icountobdds] = m_mainform.OBD_klbjqyc.Length < 1 ? "0" : m_mainform.OBD_klbjqyc;
                    objasmobds.ObdEGR[icountobdds] = m_mainform.OBD_egrkd.Length < 1 ? "0" : m_mainform.OBD_egrkd;
                    objasmobds.ObdEFI[icountobdds] = m_mainform.OBD_rypsyl.Length < 1 ? "0" : m_mainform.OBD_rypsyl;
                    objasmobds.obdjcsj[icountobdds] = dtimeobddq.ToString("yyyy-MM-dd HH:mm:ss");
                    icountobdds++;
                    if (bthread3)
                    {
                        break;
                    }
                    if (m_mainform.DateDiff(DateTime.Now, sendDate2) > 1500 && m_mainform.sconnetname.Contains("安车") && byw)
                    {
                        sendDate2 = DateTime.Now;
                        //if (m_mainform.sconnetname.Contains("安车") && byw)
                        {

                            fywrg = float.Parse((fywrg + m_mainform.getRandom(1, 5) * 0.05f).ToString("0.00"));

                            if (fywrg > 110)
                            {
                                fywrg = float.Parse((110 + m_mainform.getRandom(1, 5) * 0.05f).ToString("0.00"));
                            }
                        }
                    }
                    Thread.Sleep(500);
                }
                //lzj
            }
            
            
        }


        private void TESTZYJS_Resize(object sender, EventArgs e)
        {

            float newx = (this.Width) / x;
            float newy = (this.Height) / y;
            setControls(newx, newy, this);
        }


        public double floTodou(float m_float)
        {
            double m_dou = 0;
            double.TryParse(string.Format("{0}", m_float), out m_dou);
            return m_dou;
        }
        public double intTodou(int m_float)
        {
            double m_dou = 0;
            double.TryParse(string.Format("{0}", m_float), out m_dou);
            return m_dou;
        }



        private void TESTZYJS_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (ZYJS_Start)
            {
                t1.Abort();
                t1.DisableComObjectEagerCleanup();
                t2.Abort();
                t2.DisableComObjectEagerCleanup();

                t3.Abort();
                t3.DisableComObjectEagerCleanup();

            }

        }


        private void skinBut_ksjc_Click(object sender, EventArgs e)
        {
            skinBut_ksjc.Enabled = false;
            bthread3 = false;
            bthread_time = false;
            bsenddate = false;
            sendDate = DateTime.Now;
            sendDate2 = DateTime.Now;
            dtgcsj = DateTime.Now;
            igcsjcount_obd = 1;
            igcsjcount = 1;

            t1 = new Thread(new ThreadStart(Thread1));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();

            t2 = new Thread(new ThreadStart(Thread2));
            t2.Priority = ThreadPriority.BelowNormal;
            t2.Start();

            t3 = new Thread(new ThreadStart(Thread3));
            t3.Priority = ThreadPriority.Lowest;
            t3.Start();

        }

        private void skinBut_zjjc_Click(object sender, EventArgs e)
        {
            控制流程.flowcrtl.iquanjuzhuangtai = 0;
            bthread3 = true;
            ZYJS_Stop = true;
            ZYJS_tz = true;
            this.Close();
        }

        private void skinBut_sz_Click(object sender, EventArgs e)
        {
            ZYJSPeiZhi obj = new ZYJSPeiZhi();
            obj.ShowDialog();
        }
        //记录自由加速过程数据
        public void baocunGCSJ_ZYJS(string sjylsh, string stime)
        {
            string cysx = "";
            string ydzds = "";
            string fdjdszs = "";
            string yw = "";
            string sjxl = "";
            string jczt = "";
            string gklx = "1";
            string swendu = "";
            string sshidu = "";
            string sdaqiya = "";

            int icount = 1;
            for (int i = 0; i < 4; i++)
            {
                for (int k = 0; k < 13; k++)
                {
                    if (i == 0 && k < 3)
                    {
                        gklx = "1";
                    }
                    else if (i == 1 && k < 3)
                    {
                        gklx = "2";
                    }
                    else if (i == 2 && k < 3)
                    {
                        gklx = "3";
                    }
                    else if (i == 3 && k < 3)
                    {
                        gklx = "4";
                    }
                    if (k > 2)
                    {
                        gklx = "0";
                    }

                    if (i == 0 && k == 0)
                    {
                        cysx = string.Format(@"{0}", icount);
                        ydzds = string.Format(@"{0}", m_SKGCSJK[i, k]);
                        fdjdszs = string.Format(@"{0}", m_SKGCSJTurn[i, k]);
                        yw = string.Format(@"{0}", m_SKGCSJyw[i, k]);
                        sjxl = string.Format(@"{0}", m_SKGCSJTime[i, k]);
                        jczt = string.Format(@"{0}", gklx);
                        swendu = string.Format(@"{0}", fwendu);
                        sshidu = string.Format(@"{0}", fshidu);
                        sdaqiya = string.Format(@"{0}", fdaqiya);


                        icount++;
                    }
                    else
                    {
                        if (i < 3)
                        {
                            cysx = cysx + "," + string.Format(@"{0}", icount);
                            ydzds = ydzds + "," + string.Format(@"{0}", m_SKGCSJK[i, k]);
                            fdjdszs = fdjdszs + "," + string.Format(@"{0}", m_SKGCSJTurn[i, k]);
                            yw = yw + "," + string.Format(@"{0}", m_SKGCSJyw[i, k]);
                            sjxl = sjxl + "," + string.Format(@"{0}", m_SKGCSJTime[i, k]);
                            jczt = jczt + "," + string.Format(@"{0}", gklx);
                            swendu = swendu + "," + string.Format(@"{0}", fwendu);
                            sshidu = sshidu + "," + string.Format(@"{0}", fshidu);
                            sdaqiya = sdaqiya + "," + string.Format(@"{0}", fdaqiya);
                            icount++;
                        }
                        else
                        {
                            if (k < 3)
                            {
                                cysx = cysx + "," + string.Format(@"{0}", icount);
                                ydzds = ydzds + "," + string.Format(@"{0}", m_SKGCSJK[i, k]);
                                fdjdszs = fdjdszs + "," + string.Format(@"{0}", m_SKGCSJTurn[i, k]);
                                yw = yw + "," + string.Format(@"{0}", m_SKGCSJyw[i, k]);
                                sjxl = sjxl + "," + string.Format(@"{0}", m_SKGCSJTime[i, k]);
                                jczt = jczt + "," + string.Format(@"{0}", gklx);
                                swendu = swendu + "," + string.Format(@"{0}", fwendu);
                                sshidu = sshidu + "," + string.Format(@"{0}", fshidu);
                                sdaqiya = sdaqiya + "," + string.Format(@"{0}", fdaqiya);
                                icount++;
                            }
                        }
                    }
                }
            }








            ///保存数据库中
            string sql;
            sql = string.Format(@"Select *  from GCSJ_ZYJS where jylsh='{0}' and  time='{1}'", sjylsh, stime);
            DataTable dt = m_mainform.objbass.objdb.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                sql = string.Format(@"update GCSJ_ZYJS  set GCSJ_ZYJS_ydzds='{0}',
                                                        GCSJ_ZYJS_fdjdszs='{1}',
                                                        GCSJ_ZYJS_yw='{2}',
                                                        GCSJ_ZYJS_hjwd='{3}',
                                                        GCSJ_ZYJS_dqyl='{4}',
                                                        GCSJ_ZYJS_xdsd='{5}',
                                                        GCSJ_ZYJS_sjxl='{6}',
                                                        jczt='{9}'
                                                        where jylsh='{7}' and  time='{8}' ",
                                                        ydzds,
                                                        fdjdszs,
                                                        yw,
                                                        swendu,
                                                        sdaqiya,
                                                        sshidu,
                                                        sjxl,
                                                        sjylsh,
                                                        stime,
                                                        jczt);


            }
            else
            {

                sql = string.Format(@"insert into GCSJ_ZYJS (jylsh
                                                ,time
                                                ,GCSJ_ZYJS_ydzds
                                                ,GCSJ_ZYJS_fdjdszs
                                                ,GCSJ_ZYJS_yw
                                                ,GCSJ_ZYJS_hjwd
                                                ,GCSJ_ZYJS_dqyl
                                                ,GCSJ_ZYJS_xdsd
                                                ,GCSJ_ZYJS_sjxl
                                                ,jczt) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}',
                                                '{4}',
                                                '{5}',
                                                '{6}',
                                                '{7}',
                                                '{8}',
                                                '{9}')",
                                                sjylsh,
                                                stime,
                                                ydzds,
                                                fdjdszs,
                                                yw,
                                                swendu,
                                                sdaqiya,
                                                sshidu,
                                                sjxl,
                                                jczt);
            }
            m_mainform.objbass.objdb.InsertDB(sql);
            //


        }
        public void baocunGCSJ_OBD(string sjylsh)
        {
            string sobdgcsj_jqmkd = "";
            string sobdgcsj_fh = "";
            string sobdgcsj_qycgqxh = "";
            string sobdgcsj_glkqxs = "";
            string sobdgcsj_ymkd = "";
            string sobdgcsj_cs = "";
            string sobdgcsj_fdjzs = "";
            string sobdgcsj_jql = "";
            string sobdgcsj_jqyl = "";
            string sobdgcsj_scgl = "";
            string sobdgcsj_zyyl = "";
            string sobdgcsj_hyl = "";
            string sobdgcsj_no = "";
            string sobdgcsj_nsbsl = "";
            string sobdgcsj_pqwd = "";
            string sobdgcsj_klbjqyc = "";
            string sobdgcsj_egrkd = "";
            string sobdgcsj_rypsyl = "";
            string sobdgcsj_sj = "";
            for (int iz = 0; iz < objasmobds.ObdThrottle.Length; iz++)
            {
                if (!string.IsNullOrWhiteSpace(objasmobds.obdjcsj[iz]))
                {
                    sobdgcsj_jqmkd = sobdgcsj_jqmkd + "" + ",";
                    sobdgcsj_fh = sobdgcsj_fh + "" + ",";
                    sobdgcsj_qycgqxh = sobdgcsj_qycgqxh + "" + ",";
                    sobdgcsj_glkqxs = sobdgcsj_glkqxs + "" + ",";
                    sobdgcsj_ymkd = sobdgcsj_ymkd + objasmobds.ObdThrottle[iz] + ",";
                    sobdgcsj_cs = sobdgcsj_cs + objasmobds.ObdSpeed[iz] + ",";
                    sobdgcsj_fdjzs = sobdgcsj_fdjzs + objasmobds.ObdRPM[iz] + ",";
                    sobdgcsj_jql = sobdgcsj_jql + objasmobds.ObdAirInput[iz] + ",";
                    sobdgcsj_jqyl = sobdgcsj_jqyl + "" + ",";
                    sobdgcsj_scgl = sobdgcsj_scgl + objasmobds.ObdPower[iz] + ",";
                    sobdgcsj_zyyl = sobdgcsj_zyyl + objasmobds.ObdBoostPressure[iz] + ",";
                    sobdgcsj_hyl = sobdgcsj_hyl + objasmobds.ObdFuelConsumption[iz] + ",";
                    sobdgcsj_no = sobdgcsj_no + objasmobds.ObdNOx[iz] + ",";
                    sobdgcsj_nsbsl = sobdgcsj_nsbsl + objasmobds.ObdSCR[iz] + ",";
                    sobdgcsj_pqwd = sobdgcsj_pqwd + objasmobds.ObdEGT[iz] + ",";
                    sobdgcsj_klbjqyc = sobdgcsj_klbjqyc + objasmobds.ObdDPF[iz] + ",";
                    sobdgcsj_egrkd = sobdgcsj_egrkd + objasmobds.ObdEGR[iz] + ",";
                    sobdgcsj_rypsyl = sobdgcsj_rypsyl + objasmobds.ObdEFI[iz] + ",";
                    sobdgcsj_sj = sobdgcsj_sj + objasmobds.obdjcsj[iz] + ",";
                }
            }

            sobdgcsj_jqmkd = sobdgcsj_jqmkd.TrimEnd(',');
            sobdgcsj_fh = sobdgcsj_fh.TrimEnd(',');
            sobdgcsj_qycgqxh = sobdgcsj_qycgqxh.TrimEnd(',');
            sobdgcsj_glkqxs = sobdgcsj_glkqxs.TrimEnd(',');
            sobdgcsj_ymkd = sobdgcsj_ymkd.TrimEnd(',');
            sobdgcsj_cs = sobdgcsj_cs.TrimEnd(',');
            sobdgcsj_fdjzs = sobdgcsj_fdjzs.TrimEnd(',');
            sobdgcsj_jql = sobdgcsj_jql.TrimEnd(',');
            sobdgcsj_jqyl = sobdgcsj_jqyl.TrimEnd(',');
            sobdgcsj_scgl = sobdgcsj_scgl.TrimEnd(',');
            sobdgcsj_zyyl = sobdgcsj_zyyl.TrimEnd(',');
            sobdgcsj_hyl = sobdgcsj_hyl.TrimEnd(',');
            sobdgcsj_no = sobdgcsj_no.TrimEnd(',');
            sobdgcsj_nsbsl = sobdgcsj_nsbsl.TrimEnd(',');
            sobdgcsj_pqwd = sobdgcsj_pqwd.TrimEnd(',');
            sobdgcsj_klbjqyc = sobdgcsj_klbjqyc.TrimEnd(',');
            sobdgcsj_egrkd = sobdgcsj_egrkd.TrimEnd(',');
            sobdgcsj_rypsyl = sobdgcsj_rypsyl.TrimEnd(',');
            sobdgcsj_sj = sobdgcsj_sj.TrimEnd(',');
            string ssql = string.Format("select * from OBD_ZGCSJ where jylsh='{0}'", sjylsh);
            DataTable dt = m_mainform.objbass.objdb.GetTable(ssql);
            if (dt.Rows.Count > 0)
            {
                ssql = string.Format(@"update OBD_ZGCSJ  set 
sobdgcsj_jqmkd='{0}'
,sobdgcsj_fh='{1}'
,sobdgcsj_qycgqxh='{2}'
,sobdgcsj_glkqxs='{3}'
,sobdgcsj_ymkd='{4}'
,sobdgcsj_cs='{5}'
,sobdgcsj_fdjzs='{6}'
,sobdgcsj_jql='{7}'
,sobdgcsj_jqyl='{8}'
,sobdgcsj_scgl='{9}'
,sobdgcsj_zyyl='{10}'
,sobdgcsj_hyl='{11}'
,sobdgcsj_no='{12}'
,sobdgcsj_nsbsl='{13}'
,sobdgcsj_pqwd='{14}'
,sobdgcsj_klbjqyc='{15}'
,sobdgcsj_egrkd='{16}'
,sobdgcsj_rypsyl='{17}'
,sobdgcsj_sj='{18}'
                                                        where jylsh='{19}'",
sobdgcsj_jqmkd
 , sobdgcsj_fh
 , sobdgcsj_qycgqxh
 , sobdgcsj_glkqxs
 , sobdgcsj_ymkd
 , sobdgcsj_cs
 , sobdgcsj_fdjzs
 , sobdgcsj_jql
 , sobdgcsj_jqyl
 , sobdgcsj_scgl
 , sobdgcsj_zyyl
 , sobdgcsj_hyl
 , sobdgcsj_no
 , sobdgcsj_nsbsl
 , sobdgcsj_pqwd
 , sobdgcsj_klbjqyc
 , sobdgcsj_egrkd
 , sobdgcsj_rypsyl
 , sobdgcsj_sj
 , sjylsh);


            }
            else
            {

                ssql = string.Format(@"insert into OBD_ZGCSJ (
                                               jylsh
                                               ,sobdgcsj_jqmkd 
 ,sobdgcsj_fh 
 ,sobdgcsj_qycgqxh 
 ,sobdgcsj_glkqxs 
 ,sobdgcsj_ymkd 
 ,sobdgcsj_cs 
 ,sobdgcsj_fdjzs 
 ,sobdgcsj_jql 
 ,sobdgcsj_jqyl 
 ,sobdgcsj_scgl 
 ,sobdgcsj_zyyl 
 ,sobdgcsj_hyl 
 ,sobdgcsj_no 
 ,sobdgcsj_nsbsl 
 ,sobdgcsj_pqwd 
 ,sobdgcsj_klbjqyc 
 ,sobdgcsj_egrkd 
 ,sobdgcsj_rypsyl 
 ,sobdgcsj_sj ) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}',
                                                '{4}',
                                                '{5}',
                                                '{6}',
                                                '{7}',
                                                '{8}',
                                                '{9}',
                                                '{10}',
                                                '{11}',
                                                '{12}',
                                                '{13}',
                                                '{14}',
                                                '{15}',
                                                '{16}',
                                                '{17}',
                                                '{18}',
                                                '{19}')",
sjylsh
, sobdgcsj_jqmkd
, sobdgcsj_fh
, sobdgcsj_qycgqxh
, sobdgcsj_glkqxs
, sobdgcsj_ymkd
, sobdgcsj_cs
, sobdgcsj_fdjzs
, sobdgcsj_jql
, sobdgcsj_jqyl
, sobdgcsj_scgl
, sobdgcsj_zyyl
, sobdgcsj_hyl
, sobdgcsj_no
, sobdgcsj_nsbsl
, sobdgcsj_pqwd
, sobdgcsj_klbjqyc
, sobdgcsj_egrkd
, sobdgcsj_rypsyl
, sobdgcsj_sj);
            }
            m_mainform.objbass.objdb.InsertDB(ssql);
        }
        public void obdsc()
        {
            string cyds = "";
            string cysx = "";
            string sjxl = "";
            string jqmkd = "";
            string fh = "";
            string qycgqxh = "";
            string glkqxs = "";
            string ymkd = "";
            string cs = "";
            string fdjzs = "";
            string jql = "";
            string jqyl = "";
            string scgl = "";
            string zyyl = "";
            string hyl = "";
            string no = "";
            string nsbsl = "";
            string pqwd = "";
            string klbjqyc = "";
            string egrkd = "";
            string rypsyr = "";
            string jczt = "";

            for (int i = 0; i <= iobd; i++)
            {
                cyds = iobd.ToString();
                cysx = (i + 1).ToString();
                sjxl = sjxl + OBD_sjxl + ",";
                jqmkd = jqmkd + OBD_jqmkd[i] + ",";
                fh = fh + OBD_fh[i] + ",";
                qycgqxh = qycgqxh + OBD_qycgqxh[i] + ",";
                glkqxs = glkqxs + OBD_glkqxs[i] + ",";
                ymkd = ymkd + OBD_ymkd[i] + ",";
                cs = cs + OBD_cs[i] + ",";
                fdjzs = fdjzs + OBD_fdjzs[i] + ",";
                jql = jql + OBD_jql[i] + ",";
                jqyl = jqyl + OBD_jqyl[i] + ",";
                scgl = scgl + OBD_scgl[i] + ",";
                zyyl = zyyl + OBD_zyyl[i] + ",";
                hyl = hyl + OBD_hyl[i] + ",";
                no = no + OBD_no[i] + ",";
                nsbsl = nsbsl + OBD_nsbsl[i] + ",";
                pqwd = pqwd + OBD_pqwd[i] + ",";
                klbjqyc = klbjqyc + OBD_klbjqyc[i] + ",";
                egrkd = egrkd + OBD_egrkd[i] + ",";
                rypsyr = rypsyr + OBD_rypsyl[i] + ",";
                //jczt      = jczt    +       [i]+",";
            }
            cyds = cyds.Trim(',');
            cysx = cysx.Trim(',');
            sjxl = sjxl.Trim(',');
            jqmkd = jqmkd.Trim(',');
            fh = fh.Trim(',');
            qycgqxh = qycgqxh.Trim(',');
            glkqxs = glkqxs.Trim(',');
            ymkd = ymkd.Trim(',');
            cs = cs.Trim(',');
            fdjzs = fdjzs.Trim(',');
            jql = jql.Trim(',');
            jqyl = jqyl.Trim(',');
            scgl = scgl.Trim(',');
            zyyl = zyyl.Trim(',');
            hyl = hyl.Trim(',');
            no = no.Trim(',');
            nsbsl = nsbsl.Trim(',');
            pqwd = pqwd.Trim(',');
            klbjqyc = klbjqyc.Trim(',');
            egrkd = egrkd.Trim(',');
            rypsyr = rypsyr.Trim(',');
            jczt = jczt.Trim(',');
            string vehispara = "";
            string stoubao = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
            stoubao = stoubao + string.Format(@"<root><head><organ>{0}</organ><jkxlh>{1}</jkxlh><jkid>{2}</jkid></head>",
                                                           m_mainform.organ,
                                                          m_mainform.jkxlh,
                                                           "GC011");
            vehispara = stoubao + string.Format(@"<body><vehispara>
                                <jylsh>{0}</jylsh>
                                <testtimes>{1}</testtimes>
                                <cyds>{2}</cyds>
                                <cysx>{3}</cysx>
                                <sjxl>{4}</sjxl>
                                <jqmkd>{5}</jqmkd>
                                <fh>{6}</fh>
                                <qycgqxh>{7}</qycgqxh>
                                <glkqxs>{8}</glkqxs>
                                <ymkd>{9}</ymkd>
                                <cs>{10}</cs>
                                <fdjzs>{11}</fdjzs>
                                <jql>{12}</jql>
                                <jqyl>{13}</jqyl>
                                <scgl>{14}</scgl>
                                <zyyl>{15}</zyyl>
                                <hyl>{16}</hyl>
                                <no>{17}</no>
                                <nsbsl>{18}</nsbsl>
                                <pqwd>{19}</pqwd>
                                <klbjqyc>{20}</klbjqyc>
                                <egrkd>{21}</egrkd>
                                <rypsyr>{22}</rypsyr>
                                <jczt>{23}</jczt>
                                 </vehispara>
			                    </body>
                                </root>",
                                   businessId,
                                   m_mainform.testtimes,
                                  cyds,
            cysx,
            sjxl,
            jqmkd,
            fh,
            qycgqxh,
            glkqxs,
            ymkd,
            cs,
            fdjzs,
            jql,
            jqyl,
            scgl,
            zyyl,
            hyl,
            no,
            nsbsl,
            pqwd,
            klbjqyc,
            egrkd,
            rypsyr,
            jczt);


            //过程数据
            WebReferenceCS.VeptsOutAccess m_vesd = new WebReferenceCS.VeptsOutAccess();
            m_vesd.Url = m_mainform.surl;
            string sgc005 = m_vesd.write(vehispara);// m_mainform.decode();
            if (!sgc005.ToUpper().Contains("<CODE>1</CODE>"))
            {

                m_mainform.baocunRJ("OBD过程数据", vehispara); //
                m_mainform.baocunRJ("OBD过程数据结果", m_mainform.decode(sgc005)); //
                //sxianshineirong = "上传OBD过程数据失败 ";
                //xianshixinxi();
                return;
            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (m_mainform.DateDiff(DateTime.Now, dtl) > itlsj * 1000)
            {
                xinxixianshi.Text = string.Format("调零结束请插入采样探头");
                threadzj = new Thread(zijian);
                threadzj.Start();
                timer1.Enabled = false;

            }
        }

        Thread threadzj;
        bool bzijian = true;
        public void zijian()
        {
            for (int i = 0; i < 2; i++)
            {
                while (true)
                {
                    m_mainform.objbtg.SendDeviceCmd(3);
                    if (!bzijian)
                    {
                        xianshineirong = string.Format(@"自检结束");
                        string sshanghangx = string.Format("自检结束");
                        string sxiahangx = string.Format("");
                        m_mainform.flowwq.LedWrite(sshanghangx, sxiahangx, 1);
                        xianshi();//
                        MethodInvoker ln = new MethodInvoker(setkaishi);
                        this.BeginInvoke(ln);
                        return;
                    }
                    Thread.Sleep(100);
                    if (i == 0)
                    {
                        xianshineirong = string.Format(@"当前{0}%检测0%", m_mainform.objbtg.m_fnssk);
                        string sshanghangx = string.Format("检测0%");
                        string sxiahangx = string.Format("当前{0}%", m_mainform.objbtg.m_fnssk);
                        m_mainform.flowwq.LedWrite(sshanghangx, sxiahangx, 1);
                        xianshi();//
                        if (m_mainform.objbtg.m_fnssk < 2)
                        {
                            Thread.Sleep(500);

                            xianshineirong = string.Format(@"0%不透光合格");
                            sshanghangx = string.Format("0%不透光合格");
                            sxiahangx = string.Format("");
                            m_mainform.flowwq.LedWrite(sshanghangx, sxiahangx, 1);
                            xianshi();//
                            Thread.Sleep(2000);
                            break;
                        }
                    }
                    else
                    {
                        xianshineirong = string.Format(@"当前{0}%检测100%", m_mainform.objbtg.m_fnssk);
                        string sshanghangx = string.Format("检测100%");
                        string sxiahangx = string.Format("当前{0}%", m_mainform.objbtg.m_fnssk);
                        m_mainform.flowwq.LedWrite(sshanghangx, sxiahangx, 1);
                        xianshi();
                        if (m_mainform.objbtg.m_fnssk > 98)
                        {
                            Thread.Sleep(500);
                            xianshineirong = string.Format(@"100%不透光合格");
                            sshanghangx = string.Format("100%不透光合格");
                            sxiahangx = string.Format("");
                            m_mainform.flowwq.LedWrite(sshanghangx, sxiahangx, 1);
                            xianshi();//
                            Thread.Sleep(2000);
                            break;
                        }
                    }
                }
            }
            {
                xianshineirong = string.Format(@"自检结束");
                string sshanghangx = string.Format("自检结束");
                string sxiahangx = string.Format("");
                m_mainform.flowwq.LedWrite(sshanghangx, sxiahangx, 1);
                xianshi();//
            }
            MethodInvoker lnex = new MethodInvoker(setkaishi);
            this.BeginInvoke(lnex);
        }
        public void setkaishi()
        {
            skinBut_ksjc.Enabled = true;
        }


        public void sendZYJSGCSJ(string businessId, string svalue)
        {

            m_mainform.objbass.senddate("HJ13", svalue);
        }

        public void sendZYJSGCSJZM(string businessId, model.ZYJS.ZYJSgcsjZM objgcsjzm)
        {
            m_mainform.objbass.zmgcsjzyjs(businessId, objgcsjzm);
        }

        public void sendZYJSJG(string businessId)
        {
            JsonData value = new LitJson.JsonData();
            value["InspectionNum"] = businessId;
            value["StationCode"] = m_mainform.stationCode;
            value["SceneCode"] = m_mainform.lineCode;
            value["VLPN"] = m_mainform.VLPN;
            value["VLPNColor"] = m_mainform.VLPNColor;
            value["VIN"] = m_mainform.VIN;
            value["InspectionOperator"] = m_mainform.InspectionOperator;
            value["InspectionDriver"] = m_mainform.InspectionDriver;
            value["ICheck"] = m_mainform.InspectionOperator;
            value["CheckTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            value["Temperature"] = fwendu;
            value["Pressure"] = fdaqiya;
            value["Humidity"] = fshidu;
            value["IUTID"] = string.Format("{0}{1}{2}", m_mainform.stationCode, m_mainform.lineCode, m_mainform.IUTID);
            value["IUIDATE"] = DateTime.Now.ToString("yyyy-MM-dd");
            value["DetectStartTime"] = timeStart;
            value["DetectEndTime"] = timeEnd;
            value["VDCT"] = fSKPJ > m_mainform.InspectionLimits ? "0" : "1";
            value["LPSItem"] = 1;
            value["ER1"] = SK2.Text;
            value["ER2"] = SK3.Text;
            value["ER3"] = SK4.Text;
            value["ERA"] = fSKPJ;
            value["ActualRotateSpeed"] = m_SKTurn[0];
            value["EL"] = m_mainform.InspectionLimits;
            value["ED"] = fSKPJ > m_mainform.InspectionLimits ? "0" : "1";
            string svalue = value.ToJson();
            m_mainform.objbass.senddate("HJ14", svalue);
        }

        private void TESTZYJS_Load(object sender, EventArgs e)
        {
            bobdhg = false;
            控制流程.flowcrtl.iquanjuzhuangtai = 1;
        }

        private void TESTZYJS_FormClosing(object sender, FormClosingEventArgs e)
        {

            控制流程.flowcrtl.iquanjuzhuangtai = 0;
        }

        float fywrg = 0;
        bool byw = false;
        private void 油温人工确认ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string sql = string.Format(@"
CREATE TABLE [dbo].[ywrgqr](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[jylsh] [varchar](50) NULL,
	[hphm] [varchar](50) NULL,
	[yuanyin] [varchar](500) NULL,
	[czy] [varchar](50) NULL,
	[yw] [real] NULL,
	[lrtime] [datetime] NULL
) ON [PRIMARY]");
            try
            {
                m_mainform.objbass.objdb.InsertDB(sql);
            }
            catch (Exception ) { }

            尾气流程仪表.youwenrengong f = new 尾气流程仪表.youwenrengong();
            f.slsh = businessId;
            f.shphm = hphm.Text;
            f.scaozuoyuan = m_mainform.InspectionOperator;
            if (f.ShowDialog() == DialogResult.OK)
            {
                byw = true;
                fywrg = f.fyw;
                sql = string.Format("insert into ywrgqr (jylsh,hphm,yuanyin,czy,yw,lrtime) values ('{0}','{1}','{2}','{3}',{4},'{5}')",
                    f.slsh, f.shphm, f.syuanyin, f.scaozuoyuan, f.fyw, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                m_mainform.objbass.objdb.InsertDB(sql);
            }
        }

        private void form_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F6)
            {
                oBD上传ToolStripMenuItem.Visible = true;
                跳过自检ToolStripMenuItem.Visible = true;
            }

        }

        private void form_KeyUp(object sender, KeyEventArgs e)
        {
            oBD上传ToolStripMenuItem.Visible = false;
            跳过自检ToolStripMenuItem.Visible = false;
        }

        private void contextMenuStrip1_Closed(object sender, ToolStripDropDownClosedEventArgs e)
        {
            oBD上传ToolStripMenuItem.Visible = false;
            跳过自检ToolStripMenuItem.Visible = false;
        }

        bool bobdhg = false;
        private void oBD上传ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bobdhg = true;
        }

        bool bzsbw = false;
        private void 转速取值不稳ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bzsbw = true;
        }

        private void 跳过自检ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bzijian = false;
        }
    }
}
